package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Message;
import cn.wolfcode.trip.base.mapper.MessageMapper;
import cn.wolfcode.trip.base.query.MessageQueryObject;
import cn.wolfcode.trip.base.service.IMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements IMessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public void save(Message message) {
        messageMapper.insert(message);
    }

    @Override
    public void changeState(MessageQueryObject qo) {
        messageMapper.changeState(qo);
    }

    @Override
    public int countForType(MessageQueryObject qo) {
        return messageMapper.countForType(qo);
    }

    @Override
    public PageInfo listUread(MessageQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Message> messageList = messageMapper.queryForUread(qo);

        return new PageInfo(messageList);
    }

    @Override
    public List<Map> countForMsg(MessageQueryObject qo) {
        return messageMapper.countForMsg(qo);
    }
}
